package com.suntop.carousel.qlmediaplay.tools;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Environment;

import com.bumptech.glide.Glide;
import com.bumptech.glide.GlideBuilder;
import com.bumptech.glide.Registry;
import com.bumptech.glide.annotation.GlideModule;
import com.bumptech.glide.load.engine.cache.DiskLruCacheFactory;
import com.bumptech.glide.module.AppGlideModule;

import java.io.File;

import androidx.annotation.NonNull;
@SuppressLint("NewApi")
@GlideModule
public class MyGlide extends AppGlideModule {
    @Override
    public void applyOptions(@NonNull Context context, @NonNull GlideBuilder builder) {
        super.applyOptions(context, builder);
        int size=1024*1024*1024;
        File externalFilesDir =
                context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS);
        if (!externalFilesDir.exists()){
            boolean mkdirs = externalFilesDir.mkdirs();
        }
        builder.setDiskCache(new DiskLruCacheFactory(externalFilesDir.getAbsolutePath(),size));

    }

    @Override
    public void registerComponents(@NonNull Context context, @NonNull Glide glide, @NonNull Registry registry) {
        super.registerComponents(context, glide, registry);
    }
}
